<template>
  <div class="app-container">
    <el-form :inline="true" :model="formInline" ref="formInline" class="demo-form-inline">
      <el-form-item class="with-pre-select" label="账号" prop="target_account">
        <el-input v-model="formInline.target_account" class="input-with-select" placeholder="请输入账号" @keyup.enter.native="handleFilter" >
        </el-input>
      </el-form-item>
      <el-form-item class="with-pre-select" label="昵称" prop="target_nick"  >
        <el-input v-model="formInline.target_nick" class="input-with-select" placeholder="请输入昵称"  @keyup.enter.native="handleFilter">
        </el-input>
      </el-form-item>
      <el-form-item label="会员类型" prop="target_type">
        <el-select v-model="formInline.target_type" placeholder="会员类型">
          <el-option
            v-for="item in typeList"
            :label="item.title"
            :key="item.value"
            :value="item.value"

          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item class="with-pre-select" prop="number">
        <el-input placeholder="请输入次数" v-model="formInline.number" class="input-with-select" @keyup.enter.native="handleFilter">
          <el-select v-model="formInline.searchType" slot="prepend" placeholder="全部">
            <el-option label="全部" :value="-1"></el-option>
            <el-option label="举报次数>=" :value="1"></el-option>
            <el-option label="举报次数<" :value="2"></el-option>
          </el-select>
        </el-input>
      </el-form-item>
      <el-form-item label="最后发送时间" prop="time">
        <el-date-picker
          v-model="formInline.time"
          type="datetimerange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          :picker-options="pickerDayStep">
        </el-date-picker>
      </el-form-item>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
      <el-button @click="cancel('formInline')">重置</el-button>
    </el-form>
  </div>

</template>

<script>
import { resetForm, pickerOption } from '@/build';

export default {
  name: 'form-logs-filter',
  mixins: [resetForm, pickerOption],
  data() {
    return {
      typeList: [
        { title: '全部', value: '' },
        { title: '本站会员', value: '0' },
        { title: '外部拉取', value: '1' },
      ],
      formInline: {
        time: [
          moment().format('YYYY-MM-DD 00:00:00'),
          moment().format('YYYY-MM-DD 23:59:59'),
        ],
        target_account: undefined,
        target_nick: undefined,
        num_max: undefined,
        num_min: undefined,
        number: '',
        searchType: -1,
        target_type: undefined, // 0 本站会员 1外部拉取
        page: 1,
        size: 20,
      },
    };
  },
  methods: {
    handleFilter() {
      const reg = /^[1-9]\d*$/;
      if (this.formInline.searchType != -1 && this.formInline.number) {
        const reg = /^[1-9]\d*$/;
        if (!reg.test(this.formInline.number)) {
          this.$message({
            message: '举报次数格式不正确',
            type: 'error',
          });
          return;
        }
      }
      this.$emit('on-filter', this.formInline);
    },
    cancel(formName) {
      this.formInline.searchType = -1;
      this.formInline.number = null;
      this.formInline.num_max = undefined;
      this.formInline.num_min = undefined;
      this.resetForm(formName);
      this.handleFilter();
    },
  },
};
</script>

<style lang="scss" scoped>
  .with-pre-select {
    .el-input-group__prepend {
      .el-select {
        width: 120px;
      }
    }
  }

  .money-range {
    .el-input {
      width: 100px;
    }
  }

</style>
